package Q433

import java.util.Objects

import java.util.ArrayList


/**
 * 最小基因变化
 */
class Main {

}

fun main() {
    for(i in 0..7){
        println(i)
    }

    for(i in 0 until 7){
        println(i)
    }
}

class Solution {
    fun minMutation(start: String, end: String?, bank: Array<String>): Int {
        if (start == end) {
            return 0
        }
        if (bank.size == 0) {
            return -1
        }
        val list = ArrayList<String>()
        list.add(start)
        val def = IntArray(bank.size)
        var times = 0
        while (!list.isEmpty()) {
            ++times
            for (i in list.indices) {
                for (j in bank.indices) {
                    if (def[j] != 1 && des(list[0], bank[j]) == 1) {
                        if (end == bank[j]) {
                            return times
                        } else {
                            def[j] = 1
                            list.add(bank[j])
                        }
                    }
                }
                list.removeAt(0)
            }
        }
        return -1
    }

    fun des(a: String, b: String): Int {
        var p = 0
        for (i in 0..7) {
            if (a[i] != b[i]) {
                ++p
            }
        }
        return p
    }
}